﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebUsers.Visitor
{
    public partial class TravelsList : BasePageVisitor
    {
        NJL.BLL.NJL_NEWS bllNews = new BLL.NJL_NEWS();
        NJL.BLL.NJL_CS_NEWS_TYPE bllNewsType = new BLL.NJL_CS_NEWS_TYPE();
        NJL.Model.NJL_CS_NEWS_TYPE modelNewsType;
        NJL.BLL.NJL_USER bllUser = new BLL.NJL_USER();
        NJL.Model.NJL_USER modelUserHost;
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                modelUserHost = bllUser.GetModel(Request.QueryString["uid"]);
                Page.Title = "游记-" + modelUserHost.USER_NAME + "的乡间小屋";
                if (Request.QueryString["typeId"] == null)
                {
                    ds = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "'");
                    if (ds.Tables[0].Rows.Count > 6)
                    {
                        pager.InnerHtml = Royalsoft.Common.Pager.GetPageNum(ds, rptTravel, 6, new string[] { "uid" }, "/wanjia/yjlb-");
                    }
                    else
                    {
                        rptTravel.DataSource = ds;
                        rptTravel.DataBind();
                    }
                }
                else
                {
                    ds = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "' and TYPE_CODE='" + Request.QueryString["typeId"] + "'");
                    if (ds.Tables[0].Rows.Count > 6)
                    {
                        pager.InnerHtml = Royalsoft.Common.Pager.GetPageNum(ds, rptTravel, 6, new string[] { "uid" }, "/wanjia/yjlb-" + Request.QueryString["typeId"] + "-");
                    }
                    else
                    {
                        rptTravel.DataSource = ds;
                        rptTravel.DataBind();
                    }
                    modelNewsType = bllNewsType.GetModel(Request.QueryString["typeId"]);
                    lityjtype.Text = modelNewsType.TYPE_NAME;
                }

                litNewsCount.Text = ds.Tables[0].Rows.Count.ToString();
                #region 新闻分类
                ds = bllNewsType.GetList("TYPE_CODE<100");
                newsType.DataSource = ds;
                newsType.DataBind();
                #endregion
                #region 全部新闻
                ds = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "'");
                litAllNews.Text = ds.Tables[0].Rows.Count.ToString();
                #endregion
            }

        }
        protected void newsType_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView grv = (DataRowView)e.Item.DataItem;
                string typeCode = grv["TYPE_CODE"].ToString();
                Literal lit = e.Item.FindControl("litNewsCount") as Literal;
                ds = bllNews.GetList("NJL_PERSON_ID='" + Request.QueryString["uid"] + "' and TYPE_CODE='" + typeCode + "'");
                lit.Text = ds.Tables[0].Rows.Count.ToString();
            }
        }
    }
}